package com.tao.gulimall.product.service.impl;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tao.common.utils.PageUtils;
import com.tao.common.utils.Query;

import com.tao.gulimall.product.dao.SpuImagesDao;
import com.tao.gulimall.product.entity.SpuImagesEntity;
import com.tao.gulimall.product.service.SpuImagesService;


@Service("spuImagesService")
public class SpuImagesServiceImpl extends ServiceImpl<SpuImagesDao, SpuImagesEntity> implements SpuImagesService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SpuImagesEntity> page = this.page(
                new Query<SpuImagesEntity>().getPage(params),
                new QueryWrapper<SpuImagesEntity>()
        );

        return new PageUtils(page);
    }


	/**
	 * 商品图集保存
	 * @param id
	 * @param images
	 */
	@Override
	public void saveImages(Long id, List<String> images) {
		if(images == null || images.size() != 0){
			return;
		}else {
			List<SpuImagesEntity> spuImagesEntities = images.stream().map(item -> {

				SpuImagesEntity imagesEntity = new SpuImagesEntity();
				imagesEntity.setSpuId(id);
//				imagesEntity.setDefaultImg();
				imagesEntity.setImgUrl(item);
//				imagesEntity.setImgName();
//				imagesEntity.setImgSort();
				return imagesEntity;
			}).collect(Collectors.toList());
			this.saveBatch(spuImagesEntities);

		}
	}

}